#!/bin/bash

k=0
for n in $@
do
	if [[ ${#COORD[@]} -eq 10 ]]; then
		echo "You have entered too much coordinates!!! Only 10 ships will be printed!"
		break
	fi
	if [[ $n =~ ^[0-9]{4}$ ]]; then
		COORD[$k]=$n
		k=$k+1
	fi
done
echo ${COORD[@]}


function Print(){
echo ""
echo "0 1 2 3 4 5 6 7 8 9"
for ((i=0;i<10;i++));
do
	for ((j=0;j<10;j++));
	do
		echo -n "${field[i*10+j]} "
	done
	echo "$i"
done
}

function EmptyField(){
for ((i=0;i<10;i++));
do
	for ((j=0;j<10;j++));
	do
		field[i*10+j]="/"
	done
done
}

function SetShips(){
for ((c=0; c<=${#COORD[@]}; c++));
do
	g1=${COORD[c]:0:1}+0
	v1=${COORD[c]:1:1}+0
	g2=${COORD[c]:2:1}+0
	v2=${COORD[c]:3:1}+0
	if [[ g1 -eq g2 && v2-v1 -lt 4 || v1 -eq v2 && g2-g1 -lt 4 ]]; 
	then
		for ((i=$g1;i<=$g2;i++));
		do
			for ((j=$v1;j<=$v2;j++));
			do
				field[i*10+j]="&"
			done
		done
	else
		echo "The ship with incorrect coordinates ${COORD[c]} will not be printed! "
	fi
done
}
EmptyField
SetShips
Print

